package com.vallis.lottery.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.vallis.lottery.domain.LotteryTicket;
import com.vallis.lottery.service.ILotteryTicketService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vallis.common.annotation.Log;
import com.vallis.common.core.controller.BaseController;
import com.vallis.common.core.domain.AjaxResult;
import com.vallis.common.enums.BusinessType;

import com.vallis.common.utils.poi.ExcelUtil;
import com.vallis.common.core.page.TableDataInfo;

/**
 * 票库Controller
 *
 * @author vallis
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/lottery/ticket")
public class LotteryTicketController extends BaseController
{
    @Autowired
    private ILotteryTicketService lotteryTicketService;

    /**
     * 查询票库列表
     */
    @PreAuthorize("@ss.hasPermi('lottery:ticket:list')")
    @GetMapping("/list")
    public TableDataInfo list(LotteryTicket lotteryTicket)
    {
        startPage();
        List<LotteryTicket> list = lotteryTicketService.selectLotteryTicketList(lotteryTicket);
        return getDataTable(list);
    }

    /**
     * 导出票库列表
     */
    @PreAuthorize("@ss.hasPermi('lottery:ticket:export')")
    @Log(title = "票库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LotteryTicket lotteryTicket)
    {
        List<LotteryTicket> list = lotteryTicketService.selectLotteryTicketList(lotteryTicket);
        ExcelUtil<LotteryTicket> util = new ExcelUtil<LotteryTicket>(LotteryTicket.class);
        util.exportExcel(response, list, "票库数据");
    }

    /**
     * 获取票库详细信息
     */
    @PreAuthorize("@ss.hasPermi('lottery:ticket:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(lotteryTicketService.getById(id));
    }

    /**
     * 新增票库
     */
    @PreAuthorize("@ss.hasPermi('lottery:ticket:add')")
    @Log(title = "票库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LotteryTicket lotteryTicket) {
        return toAjax(lotteryTicketService.save(lotteryTicket));
    }

    /**
     * 修改票库
     */
    @PreAuthorize("@ss.hasPermi('lottery:ticket:edit')")
    @Log(title = "票库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LotteryTicket lotteryTicket) {
        return toAjax(lotteryTicketService.updateById(lotteryTicket));
    }

    /**
     * 删除票库
     */
    @PreAuthorize("@ss.hasPermi('lottery:ticket:remove')")
    @Log(title = "票库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(lotteryTicketService.removeByIds(Arrays.asList(ids)));
    }
}
